const { ccclass, property } = cc._decorator;
declare let eManager,dbh,DBManager,i18n,JsonHttp;
import BaseView from "../../component/BaseView";
import QuDou from "./../QuDou";
import MianMo from "./../MianMo";
import MoFenDi from "./../MoFenDi";
import CaLian from "./../CaLian";
import UIHelper = require("../../component/UIHelper");

//挤痘+化妆
@ccclass
export default class HuaZhuangThreeView extends BaseView {
    //触摸区域
    @property(cc.Node)
    bg: cc.Node = null;
    //祛痘
    @property(QuDou)
    QuDou: QuDou = null;
    //面膜
    @property(MianMo)
    MianMo: MianMo = null;
    //抹粉底
    @property(MoFenDi)
    MoFenDi: MoFenDi = null;
    //擦脸
    @property(CaLian)
    CaLian: CaLian = null;


    //下一步
    @property(cc.Node)
    nodeNextPoint: cc.Node = null;
    //完成
    @property(cc.Node)
    nodeDone: cc.Node = null;

    @property(cc.Node)
    btnClose: cc.Node = null;

    _point = 1;
    _isPlay = false;
    _isStart = false;//是否是剧情前触发
    onLoad() {
        super.onLoad();
        this.bg.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.bg.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.bg.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        eManager.on("HZ_REFRESH_ICON_TIPS", this.showIconTips, this)
        eManager.on("MINI_DONE_POINT", this.donePoint, this)
        eManager.on("MINI_DONE_STEP", this.doneStep, this)
        //@ts-ignore
        this._isStart = this.node.openParam;
    };

    onClose(){
    };

    start() {
        super.start();
        this.btnClose.active = !this._isStart;
        this.updatePointShow();
    };

    donePoint(point:number){
        this.nodeNextPoint.active = true;
    };
    doneStep(){
        this.nodeDone.active = true;
    };

    updatePointShow(){
        this.QuDou.node.active = this._point == 1;
        this.MianMo.node.active = this._point == 2;
        this.MoFenDi.node.active = this._point == 3;
        this.CaLian.node.active = this._point == 4;
        switch (this._point) {
            case 1:
                this.QuDou.initData();
                break;
            case 2:
                this.MianMo.initData();
                break;
            case 3:
                this.MoFenDi.initData();
                break;
            case 4:
                this.CaLian.initData();
                break;
        }
        // Initializer.huaZhuangProxy.sendMakeDot(6,this._point,1);
    };

    //展示提示图片
    showIconTips(name){

    };

    //下一小阶段
    onClickNextPoint() {
        this.nodeNextPoint.active = false;
        this._point++;
        this.updatePointShow();
    };

    onTouchStart(event) {
        switch (this._point) {
            case 1:
                this.QuDou._touchStart(event);
                break;
            case 2:
                this.MianMo._touchStart(event);
                break;
            case 3:
                this.MoFenDi._touchStart(event);
                break;
            case 4:
                this.CaLian._touchStart(event);
                break;
        }
    };

    onTouchMove(event) {
        switch (this._point) {
            case 1:
                this.QuDou._touchMove(event);
                break;
            case 2:
                this.MianMo._touchMove(event);
                break;
            case 3:
                this.MoFenDi._touchMove(event);
                break;
        }
    };

    onTouchEnd(event) {
        switch (this._point) {
            case 2:
                this.MianMo._touchEnd(event);
                break;
            case 4:
                this.CaLian._touchEnd(event);
                break;
        }
    };

    onClickEnd(isSkip){
        let next = this.params.next && this.params.next.shift();
        if (next) {
            UIHelper.openUI(next, {
                next: this.params.next
            })
            this.node.destroy();
        }
    };

    onClickSkip(){
        this.onClickEnd(true);
    };

}
